// 简单的请求日志中间件
const logger = (req, res, next) => {
  const start = new Date();
  const { method, url, ip } = req;
  
  // 记录请求开始
  console.log(`[${start.toISOString()}] ${method} ${url} - 来自 ${ip}`);
  
  // 响应发送后的操作
  res.on('finish', () => {
    const duration = new Date() - start;
    console.log(`[${new Date().toISOString()}] ${method} ${url} - ${res.statusCode} - ${duration}ms`);
  });
  
  next();
};

module.exports = logger; 